/**
 * 认证域
 * @author wuxie QQ:16349023
 * @date 2019-3-22
 */
define('AuthorizingRealm',['siteConfig','TokenStore'], function (siteConfig, tokenStore) {
    let AuthorizingRealm=function (siteConfig) {
        this.siteConfig=siteConfig;
    }
    // 未登录处理
    AuthorizingRealm.prototype.unLoginHandler= function (to, from, next) {
        if (this.siteConfig.authorizeType === 'remote') {
            location.href = this.siteConfig.authorizeUrl
            next(false)
        } else {
            // context.setRedirectUri(to.path)
            let redirectUrl=this.siteConfig.baseUrl + '#' + to.path;
            location.href = this.siteConfig.localLoginUrl + '&redirect_uri=' + encodeURIComponent(redirectUrl)
        }
    }
    // 未认证处理
    AuthorizingRealm.prototype.unAuthorized=function (options) {
        if (this.siteConfig.authorizeType === 'remote') {
            location.href = this.siteConfig.authorizeUrl
        } else {
            let redirectUrl=encodeURIComponent(this.baseUrl);
            location.href = this.siteConfig.localLoginUrl + '&redirect_uri=' + redirectUrl
        }
    }
    return new AuthorizingRealm(siteConfig);
})